import { observable, action, useStrict, computed, asMap, toJS } from 'mobx';

export default class BaseStore{

    @observable variableMap = observable.map ? observable.map({}) : asMap({});

    constructor(){
        this.controlVariableMap = this.controlVariableMap.bind(this);
        this.batchControlVariableMap = this.batchControlVariableMap.bind(this);
        this.changeState = this.changeState.bind(this);
    }

    @action('批量控制变量区')
    batchControlVariableMap(obj={}){
        Object.keys(obj).forEach(key =>{
            this.controlVariableMap(key, obj[key]);
        });
    }

    @action('控制变量区')
    controlVariableMap(key, value){
        this.variableMap.set(key, value);
    }

    @action('重置变量区')
    resetVariableMap(){
        this.variableMap = observable.map ? observable.map({}) : asMap({});
    }

    @action
    changeState(params = {}) {
        Object.keys(params).forEach(key => {
            this[key] = params[key];
        });
        return this;
    }
    
}